Skip to content

Track max buffer usage in memory channel statistics - #3474

Merged
A5rocks merged 3 commits into
python-trio:mainfrom
pctablet505:track-max-buffer-used-1723
Aug 11, 2026
Merged

Track max buffer usage in memory channel statistics#3474
A5rocks merged 3 commits into
python-trio:mainfrom
pctablet505:track-max-buffer-used-1723

Conversation

@pctablet505

Copy link
Copy Markdown
Contributor

Adds a max_buffer_used field to MemoryChannelStatistics, tracking the largest number of items the channel's buffer has ever held at once.

The use case: when you need buffering but math.inf isn't a reasonable max_buffer_size, this makes it possible to observe real-world peak usage during a run and pick a sensible limit, instead of guessing.

Closes #1723

Add a max_buffer_used field to MemoryChannelStatistics that reports
the largest number of items the channel's buffer has held at once
since it was created. This lets users pick a sensible
max_buffer_size based on data from a real run instead of guessing.

Closes python-trio#1723
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00000%. Comparing base (3769b07) to head (0a8797f).

Additional details and impacted files
@@               Coverage Diff               @@
##                 main        #3474   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files             128          128           
  Lines           19449        19458    +9     
  Branches         1320         1320           
===============================================
+ Hits            19449        19458    +9     
Files with missing lines Coverage Δ
src/trio/_channel.py 100.00000% <100.00000%> (ø)
src/trio/_tests/test_channel.py 100.00000% <100.00000%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pctablet505
pctablet505 marked this pull request as ready for review July 17, 2026 09:40
@mikenerone

Copy link
Copy Markdown
Member

@pctablet505 One suggestion: I get that the "used" bit of max_buffer_used is you trying to be explicit about the meaning, but I'd still expect this name to confuse people. max_anything sounds like a configured limit rather than a metric. I'd suggest something like peak_buffer or peak_buffer_used.

pctablet505 and others added 2 commits July 27, 2026 15:12
max_buffer_used read as a configured limit rather than a runtime metric,
easily confused with max_buffer_size. peak_buffer_used pairs more clearly
with the existing current_buffer_used field.
@A5rocks
A5rocks merged commit a443d4e into python-trio:main Aug 11, 2026
48 checks passed
@trio-bot

trio-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

Hey @pctablet505, it looks like that was the first time we merged one of your PRs! Thanks so much! 🎉 🎂

If you want to keep contributing, we'd love to have you. So, I just sent you an invitation to join the python-trio organization on Github! If you accept, then here's what will happen:

  • Github will automatically subscribe you to notifications on all our repositories. (But you can unsubscribe again if you don't want the spam.)

  • You'll be able to help us manage issues (add labels, close them, etc.)

  • You'll be able to review and merge other people's pull requests

  • You'll get a [member] badge next to your name when participating in the Trio repos, and you'll have the option of adding your name to our member's page and putting our icon on your Github profile (details)

If you want to read more, here's the relevant section in our contributing guide.

Alternatively, you're free to decline or ignore the invitation. You'll still be able to contribute as much or as little as you like, and I won't hassle you about joining again. But if you ever change your mind, just let us know and we'll send another invitation. We'd love to have you, but more importantly we want you to do whatever's best for you.

If you have any questions, well... I am just a humble Python script, so I probably can't help. But please do post a comment here, or in our chat, or on our forum, whatever's easiest, and someone will help you out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: track max queue length in memory channel stats

5 participants